/*
 * ===================================================
 *
 *       Filename:  keymap.c
 *
 *
 *        Created:  10/22/2011 03:31:42 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  durand_y, <durand.yoan@gmail.com>
 *
 * ===================================================
 */
#include "game.h"

void            keymap(SDL_Rect     *ship_pos,
                       SDL_Surface  **ship,
                       char         *picture,
                       SDL_Surface  **screen)
{
  SDL_Event   event;
  int         play = 1;
  
  ship = ship;
  picture = picture;
  screen = screen;
  SDL_EnableKeyRepeat(10, 10);
    while (play)
    {
      SDL_PollEvent(&event);
      switch (event.type)
      {
      case SDL_QUIT:
	play = 0;
                break;
      case SDL_KEYDOWN:
	switch(event.key.keysym.sym)
	{
	case SDLK_UP:
	  ship_pos->y -= 5;
	  break;
	case SDLK_DOWN:
	  ship_pos->y += 5;
	  break;
	case SDLK_RIGHT:
	  ship_pos->x += 5;
	  break;
	case SDLK_LEFT:
	  ship_pos->x -= 5;
	  break;
	case SDLK_ESCAPE:
	  play = 0;
	  break;
	default:
	  break;
	}
            break;
      }
      background_update(*screen);
      *ship = draw_rect(ship_pos->x, ship_pos->y, picture, *screen);
      SDL_Flip(*screen);
    }
}
